package org.demo.treeeditor;

import org.boxlayout.gui.BoxLayoutEngine;
import org.boxlayout.gui.VisualElement;
import org.boxlayout.gui.type.ColorEnum;

public class NodePointer {

	
	enum State {HIDDEN,HIGHLIGHT}
	State currentState ;
	Node currentNode;
	VisualElement visual;
	BoxLayoutEngine ble;
	
	public NodePointer(BoxLayoutEngine ble) {
		this.ble = ble;
		currentState = State.HIGHLIGHT;
		visual = ble.createElement().setColor(ColorEnum.BLUE).setAlpha(0.5f).setRounded(true);
		//.setText("Pointer")
		;
	}
	
	public void setNode(Node aNode){
		currentNode = aNode;
		highlightNode(currentNode);	
		
	}
	
	public void highlightNode(Node aNode){
		VisualElement vis = aNode.getNameContainerVisualElement();
		System.out.println(vis.getId()+"_"+vis.getPreferedHeight()+"-"+vis.getPreferedWidth());
		//visual.setX(vis.getAbsoluteX()-this.visual.getWidth());
		//visual.setY(vis.getAbsoluteYCenter()+(visual.getHeight()/2));
		//visual.setZ(vis.getAbsoluteZ()+vis.getDeep());
		Float border = 0.01f;
		visual.setX(vis.getAbsoluteX()-border);
		visual.setY(vis.getAbsoluteY()+border);
		// no need layout engine auto handle Z axis according position in tree
		//visual.setZ(vis.getAbsoluteZ()+VisualElement.Z_SPACE);
		visual.setPreferedWidth(vis.getWidth()+(2*border));
		visual.setPreferedHeight(vis.getHeight()+(2*border));
		//visual.setWidth(vis.getWidth()+(2*border));
		//visual.setHeight(vis.getHeight()+(2*border));
		visual.layout();
	}
	
	public VisualElement getVisual(){
		return visual;
	}

	public Node getNode() {
		return currentNode;
	}

}
